$(function(){
	$(window).resize($.fn.resizeWindowHandler);

	$("#userLoginButton").click($.fn.userLoginClickHandler);
	$("#userOptionsButton").click($.fn.userOptionsClickHandler);
	
	$("html").click($.fn.documentClickHandler);
	
	$("#languageDialog").dialog({autoOpen:false});
	$("#languageButton").click($.fn.languageButtonClick);
	
	$.fn.resizeWindowHandler();	
	

	ErrorNotification.initialize();
	DynamicContentLoader.initialize();
	LoginManager.initialize();
	NotificationManager.initialize($("#notificationContainer"));
	InvitationManager.initialize($("#invitationContainer"));

});

function isDisplayed(object) {
	if ($(object).css('display') == 'block') {
		return true;
	}
	return false;
}

$.fn.languageButtonClick = function() {

	$("#languageDialog").dialog("open");	
};

$.fn.resizeWindowHandler = function() {
	var windowH = $(window).height();

	var contentH = $("#content").height();

	var headerH = $("#header").height();
	var footerH = $("#footer").height();

	// set content height
	contentH = windowH - headerH - footerH;
	$("#content").height(contentH);
};

$.fn.userLoginClickHandler = function(event) {
	if (!isDisplayed($("#headerUserLogin"))) {
		$("#headerUserLogin").show("fast");
	}
	event.stopPropagation();

};

$.fn.userOptionsClickHandler = function(event) {
	if (!isDisplayed($("#headerUserSelectOptions"))) {
		$("#headerUserSelectOptions").show("fast");
	}
	event.stopPropagation();
};

$.fn.markerAddClick = function(event){
	//alert('add');
	if (!isDisplayed($("#markerAddEdit"))) {
		$("#markerAddEdit").show("fast");
	}
	event.stopPropagation();
};



$.fn.documentClickHandler = function() {
	if (isDisplayed($("#headerUserLogin")))
		$("#headerUserLogin").hide("fast");
	if (isDisplayed($("#headerUserSelectOptions")))
		$("#headerUserSelectOptions").hide("fast");
};